package com.itheima.Maopao;

import java.util.ArrayList;
import java.util.Arrays;

public class Test {

    //冒泡排序最终版
    public static void main(String[] args) {

        int[] arr = {12, 5, 6, 7, 8, 9, 10, 11, 1, 2, 3, 4};


        int n = arr.length-1;
        for (int i = 0; i < arr.length-1; i++) {
            int last = 0;

            for (int j = 0; j < n; j++) {

                System.out.println("\t\t层循环，比较："+arr[j]+"和"+arr[j+1]+",当前第："+(j+1)+"次");
                if (arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    last=n;
                }
            }
            n=last;
            if (n==0){
                break;
            }

        }
        System.out.println(Arrays.toString(arr));


    }
}
